<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>获取瓦片</title>
    <script src="/Public/js/tianditu.api.js"></script>
    <script src="/Public/js/jquery-3.7.1.min.js"></script>

    <link rel="icon" href="/Public/imgs/H.ico">
    <style>
        html,
        body {
            margin: 0;
            padding: 0;
            width: 100%;
            height: 100%;
            overflow: hidden;
        }

        #map {
            position: relative;
            width: 100%;
            height: 100%;
        }

        #getDem {
            position: absolute;
            bottom: 100px;
            left: 20px;
            z-index: 450;
            width: 50px;
            height: 200x;
        }
    </style>
</head>

<body>
    <div id="map"></div>
    <button id="getDem">T</button>

    <script>
        var map = new T.Map('map',);
        map.centerAndZoom(new T.LngLat(103, 30), 12);
        map.addEventListener('click', HD1)

        async function t1() {
            // const url = 'https://t3.tianditu.gov.cn/mapservice/swdx?' +
            //     'T=elv_w&' +
            //     'tk=5174fc271848db77b921f28bb7ce5e22' +
            //     '&x=' + 3233 +
            //     '&y=' + 656 +
            //     '&l=' + 12

            const url = 'https://assets.ion.cesium.com/ap-northeast-1/asset_depot/1/CesiumWorldTerrain/v1.2/12/6439/2729.terrain?extensions=metadata&v=1.2.0'

            const response = await fetch(url);
            const arrayBuffer = await response.arrayBuffer();

            const blob = new Blob([arrayBuffer], { type: 'image/png' });
            // const handle = await window.showSaveFilePicker({
            //     suggestedName: 'a.png',
            //     types: [{
            //         description: 'PNG Image',
            //         accept: { 'image/png': ['.png'] }
            //     }]
            // });

            const handle = await window.showSaveFilePicker({
                suggestedName: 'a.tif',
                types: [{
                    description: 'Tif Image',
                    accept: { 'image/tiff': ['.tif'] }
                }]
            });

            const writable = await handle.createWritable();
            await writable.write(blob);
            await writable.close();
        }


        async function HD1(e) {
            const data1 = await t1()
        }   
    </script>
</body>

</html>